module.exports = app => {
  const mongoose = app.mongoose;
  const Schema = mongoose.Schema;
  /**
   * @ grade data schema
   */
  let GradeSchema = new Schema({
    name: String,
    value: Number,
    remark: String,
    date: { type: Number, default: Date.now }
  }, {usePushEach: true});

  GradeSchema.statics = {
    add(data) {
      return data.save();
    },
    update(id, data) {
      return this.findByIdAndUpdate({_id: id}, {$set: data}, {new: true});
    },
    findAll: function(cb) {
      return this.find({}).exec(cb);
    },
    del(id) {
      return this.remove({ _id: id }).exec();
    }
  };

  return mongoose.model('Grade', GradeSchema);
}